<?php

namespace App\Traits\Relation;

use App\Models\User;
use App\Models\Permission;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
 * 定义岗位模型关系
 *
 * Trait PositionRelation
 * @package App\Traits\Relation
 * Date: 22/03/2018
 * @author George
 */
trait PositionRelation
{
	/**
	 * 定义岗位与权限的关系
	 *
	 * Date: 22/03/2018
	 * @author George
	 * @return BelongsToMany
	 */
	public function permissions()
	{
		return $this->belongsToMany(Permission::class, 'position_permission_pivot', 'position_id', 'permission_code', 'id', 'code');
	}

	/**
	 * 定义岗位与用户的关系
	 *
	 * Date: 22/03/2018
	 * @author George
	 * @return HasMany
	 */
	public function users()
	{
		return $this->hasMany(User::class, 'position_id', 'id');
	}
}
